Imports System.ComponentModel
Imports System.Web.UI

<ToolboxData("<{0}:ConsumerPart runat=server></{0}:ConsumerPart>")> Public Class ConsumerPart
    Inherits System.Web.UI.WebControls.WebParts.WebPart

    Private ibk As IBookInfo
    Dim typ As Object
    Dim strTitle As String
    Dim pcSchema As PropertyDescriptorCollection

    <WebControls.WebParts.ConnectionConsumer("IBookInfo Consumer")> _
    Public Sub IBookInfoConsumer(ByVal bk As IBookInfo)
        Dim strProviderValue As String
        Dim bolSuccess As Boolean

        ibk = bk

        strProviderValue = "10345329"
        bk.ISBN = strProviderValue
        bk.UpdateCache(True)
        bolSuccess = bk.SortData("Desc")

    End Sub

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

        If ibk Is Nothing Then
            writer.Write("<b>No book information available.</b>")
        Else
            writer.Write("ISBN: <b>" & ibk.ISBN & "</b>")
        End If

    End Sub

    Private Sub ConsumerPart_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.Title = "Consumer"
    End Sub

    Dim ifld As WebControls.WebParts.IWebPartField

    <WebControls.WebParts.ConnectionConsumer("IWebPartField Consumer")> _
    Public Sub IWebPartFieldConsumer(ByVal fld As WebControls.WebParts.IWebPartField)

        ifld = fld
        ifld.GetFieldValue(AddressOf ReceiveData)

    End Sub

    Sub ReceiveData(ByVal BookTitle As Object)
        Dim pd As PropertyDescriptor

        pd = ifld.Schema
        If pd.PropertyType.Name = "String" Then
            strTitle = BookTitle.ToString
        End If

    End Sub


    <WebControls.WebParts.ConnectionConsumer("IWebPartParameters Consumer")> _
 Public Sub IWebPartParametersConsumer( _
                   ByVal prm As WebControls.WebParts.IWebPartParameters)
        Dim pdc As PropertyDescriptorCollection
        Dim iprm As WebControls.WebParts.IWebPartParameters

        iprm = prm

        pdc = TypeDescriptor.GetProperties(Me)
        iprm.SetConsumerSchema(pdc)

        If iprm.Schema.Count = pdc.Count Then
            iprm.GetParametersData(AddressOf ReceiveData)
        End If
    End Sub

    Sub ReceiveData(ByVal BookInfo As IDictionary)
        Dim entry As DictionaryEntry

        For Each entry In BookInfo.Keys
            Select Case entry.Key.ToString
                Case "BookTitle"
                    Me.BookTitle = entry.Value.ToString
                Case "BookAuthor"
                    Me.BookAuthor = entry.Value.ToString
            End Select
        Next

    End Sub

    Property BookTitle() As String
        Get
            Return "Custom Controls and Web Parts"
        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Property BookAuthor() As String
        Get
            Return "Peter Vogel"
        End Get
        Set(ByVal value As String)

        End Set
 End Property

End Class
